<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>全栈开发(Spring Boot Actuator) | 静待花开</title><meta name="author" content="brad 随风起舞"><meta name="copyright" content="brad 随风起舞"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Spring boot actuator介绍Spring boot actuator是Spring boot的一个子项目.Actuator模块可以在你的应用中使用生产就绪特性.Actuator会暴露不同的端点去监控应用中的指标和统计信息.使用Actuator,您可以监视运行状况，查看指标​​，收集日志，执行线程转储，了解垃圾收集，查看环境变量以及从BeanFactory查看Bean.此外，您可以使">
<meta property="og:type" content="article">
<meta property="og:title" content="全栈开发(Spring Boot Actuator)">
<meta property="og:url" content="https://zhangbo4881820.gitee.io/myblog/posts/45057/index.html">
<meta property="og:site_name" content="静待花开">
<meta property="og:description" content="Spring boot actuator介绍Spring boot actuator是Spring boot的一个子项目.Actuator模块可以在你的应用中使用生产就绪特性.Actuator会暴露不同的端点去监控应用中的指标和统计信息.使用Actuator,您可以监视运行状况，查看指标​​，收集日志，执行线程转储，了解垃圾收集，查看环境变量以及从BeanFactory查看Bean.此外，您可以使">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2019-11-07T03:20:13.000Z">
<meta property="article:modified_time" content="2023-09-07T09:44:01.888Z">
<meta property="article:author" content="brad 随风起舞">
<meta property="article:tag" content="实战">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/myblog/img/favicon.png"><link rel="canonical" href="https://zhangbo4881820.gitee.io/myblog/posts/45057/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="/myblog/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/myblog/css/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/myblog/',
  algolia: undefined,
  localSearch: {"path":"/myblog/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '全栈开发(Spring Boot Actuator)',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2023-09-07 17:44:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 7.0.0-rc2"><link rel="alternate" href="/myblog/atom.xml" title="静待花开" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/myblog/" title="静待花开"><span class="site-name">静待花开</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">全栈开发(Spring Boot Actuator)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-11-07T03:20:13.000Z" title="发表于 2019-11-07 11:20:13">2019-11-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-07T09:44:01.888Z" title="更新于 2023-09-07 17:44:01">2023-09-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/%E5%AE%9E%E6%88%98/">实战</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="全栈开发(Spring Boot Actuator)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><h1 id="Spring-boot-actuator介绍"><a href="#Spring-boot-actuator介绍" class="headerlink" title="Spring boot actuator介绍"></a>Spring boot actuator介绍</h1><p>Spring boot actuator是Spring boot的一个子项目.Actuator模块可以在你的应用中使用生产就绪特性.Actuator会暴露不同的<br>端点去监控应用中的指标和统计信息.使用Actuator,您可以监视运行状况，查看指标​​，收集日志，执行线程转储，了解垃圾收集，查看环境变量以及从BeanFactory查看Bean.此外，您可以使用它来监视应用程序的生产支持和相关内容，例如监视进程，检查运行状况，检查进程是否正在运行，检查数据库连接是否正在运行以及检查相关指标(例如堆大小或可用状态).JVM中的空间。所有这些东西<br>都由执行器负责Spring Boot提供的库可以公开一些REST端点，以便不同的监视工具可以使用这些REST端点从REST端点中获取数据。<br>您可以使用<code>&lt;host&gt;：port/actuator/&lt;endpoint&gt;</code>访问所有这些端点。<br>例如，如果要监视应用程序的运行状况，则必须访问<code>http://localhost:8080/actuator/health</code>。</p>
<h1 id="使用Actuator模块"><a href="#使用Actuator模块" class="headerlink" title="使用Actuator模块"></a>使用Actuator模块</h1><p>可以访问 (<a href="http://start.spring.io/">http://start.spring.io/</a>) 了解.注入依赖:</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;dependency&gt; </span><br><span class="line">&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; </span><br><span class="line">&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt; </span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<p>把依赖注入,那些actuator特性就可以使用了.默认情况下actuator是受保护的.可以在配置文件里面取消保护.</p>
<p><code>management.security.enabled=false</code> 不过这个方法现在已经过期了.</p>
<p>springboot2.0暴露所有端点的配置<code>management.endpoints.web.exposure.include=&quot;*&quot;</code><br><code>: Exposing 13 endpoint(s) beneath base path &#39;/actuator&#39;</code>控制台将会看到这条信息</p>
<h2 id="info"><a href="#info" class="headerlink" title="/info"></a><code>/info</code></h2><p>这个端点展示的是关于SpringBoot的任意信息,默认啥也不展示.虽然你可以重写信息,但是这个端点展示的仍然是不敏感的信息.</p>
<h2 id="env"><a href="#env" class="headerlink" title="/env"></a><code>/env</code></h2><p>这个端点返回你在JVM里配置的所有敏感信息,例如<code>&#123;&quot;local.server.port&quot;:8080&#125;</code>.换句话说,它展示了你项目运行在的那个端口号<br>它还展示一些系统属性,例如JDK和JAVA版本信息,项目的目录信息,库路径,时区,等等.还会展示你添加的配置文件的配置信息.</p>
<h2 id="metrics"><a href="#metrics" class="headerlink" title="&#x2F;metrics"></a>&#x2F;metrics</h2><p>这个端点展示来自操作系统,JVM,和应用级别的指标,例如堆内存,处理器,线程,类加载器和线程池的信息</p>
<h2 id="httpTrace"><a href="#httpTrace" class="headerlink" title="&#x2F;httpTrace"></a>&#x2F;httpTrace</h2><p>它的作用就是请求你的REST API端点留下的痕迹信息.如果需要暴露这个端点.那么需要实现HttpTraceRepository的配置类</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">/**</span><br><span class="line"> * create by zhangbo on 2019/11/7 0007</span><br><span class="line"> * &lt;p&gt;</span><br><span class="line"> * HttpTraceRepository实现这个配置,才能暴露出httptrace端点</span><br><span class="line"> */</span><br><span class="line">@Configuration</span><br><span class="line">public class InMemoryHttpTraceRepository implements HttpTraceRepository &#123;</span><br><span class="line"></span><br><span class="line">    private int capacity = 100;</span><br><span class="line"></span><br><span class="line">    private boolean reverse = true;</span><br><span class="line"></span><br><span class="line">    private final List&lt;HttpTrace&gt; traces = new LinkedList&lt;&gt;();</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * Flag to say that the repository lists traces in reverse order.</span><br><span class="line">     *</span><br><span class="line">     * @param reverse flag value (default true)</span><br><span class="line">     */</span><br><span class="line">    public void setReverse(boolean reverse) &#123;</span><br><span class="line">        synchronized (this.traces) &#123;</span><br><span class="line">            this.reverse = reverse;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * Set the capacity of the in-memory repository.</span><br><span class="line">     *</span><br><span class="line">     * @param capacity the capacity</span><br><span class="line">     */</span><br><span class="line">    public void setCapacity(int capacity) &#123;</span><br><span class="line">        synchronized (this.traces) &#123;</span><br><span class="line">            this.capacity = capacity;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public List&lt;HttpTrace&gt; findAll() &#123;</span><br><span class="line">        synchronized (this.traces) &#123;</span><br><span class="line">            return Collections.unmodifiableList(new ArrayList&lt;&gt;(this.traces));</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public void add(HttpTrace trace) &#123;</span><br><span class="line">        synchronized (this.traces) &#123;</span><br><span class="line">            while (this.traces.size() &gt;= this.capacity) &#123;</span><br><span class="line">                this.traces.remove(this.reverse ? this.capacity - 1 : 0);</span><br><span class="line">            &#125;</span><br><span class="line">            if (this.reverse) &#123;</span><br><span class="line">                this.traces.add(0, trace);</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                this.traces.add(trace);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="health"><a href="#health" class="headerlink" title="&#x2F;health"></a>&#x2F;health</h2><p>这个端点用作去检查应用的运行状态和健康情况.</p>
<p>可以通过 (<a href="http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints">http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-endpoints</a>)<br>网页获取完整指导.</p>
<h1 id="自定义端点"><a href="#自定义端点" class="headerlink" title="自定义端点"></a>自定义端点</h1><p>通过配置文件application.yaml自定义端点 <code>endpoints.[endpoint-name].[property to customize]</code></p>
<h2 id="自定义属性"><a href="#自定义属性" class="headerlink" title="自定义属性"></a>自定义属性</h2><p>三个属性可以自定义</p>
<ul>
<li><p><strong>id:</strong> 这也就是为端点弄个名字.访问这个名字.</p>
</li>
<li><p><strong>enable:</strong> 端点的访问控制属性.true可以被访问,false不能访问</p>
</li>
<li><p><strong>sensitive:</strong> 这属性对端点提供一个安全机制.true需要身份验证来展示重要信息</p>
</li>
</ul>
<p><strong>可是springboot2.0就很不一样了.</strong><br>id 对应<code>management.endpoints.web.path-mapping.health=healthcheck</code><br><code>management.endpoints.web.base-path=/</code>这个时改变基础路径.默认时/actuator<br>sensitive 对应<code>management.endpoint.health.show-details</code>是否展示详细信息<br><code>management.endpoint.health.roles=ADMIN</code> 就是需要ADMIN角色才能访问health端点.或者JAVA代码:</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">public class ActuatorSecurity extends WebSecurityConfigurerAdapter &#123;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    protected void configure(HttpSecurity http) throws Exception &#123;</span><br><span class="line">        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()</span><br><span class="line">                .anyRequest().hasRole(&quot;ENDPOINT_ADMIN&quot;)</span><br><span class="line">                .and()</span><br><span class="line">            .httpBasic();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="自定义Health指针"><a href="#自定义Health指针" class="headerlink" title="自定义Health指针"></a>自定义Health指针</h2><p>你可以实现自己的健康指针通过实现HealthIndicator接口并且重写为实现的方法.这种自定义健康指针可以收集任何指定类型的自定义健康数据并提供给/health端点.下面是代码例子:</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">/**</span><br><span class="line"> * create by zhangbo on 2019/11/8 0008</span><br><span class="line"> */</span><br><span class="line">@Component</span><br><span class="line">public class CustomHealthIndicator implements HealthIndicator &#123;</span><br><span class="line"></span><br><span class="line">    @Override</span><br><span class="line">    public Health health() &#123;</span><br><span class="line"></span><br><span class="line">        int errorCode = check();</span><br><span class="line">        if (errorCode == 0) &#123;</span><br><span class="line">            return Health.up()</span><br><span class="line">                         .withDetail(&quot;Status&quot;,&quot; UP&quot;)</span><br><span class="line">                         .withDetail(&quot;Error Code&quot;,errorCode)</span><br><span class="line">                         .withDetail(&quot;Description&quot;,&quot;自定义健康指针指向UP&quot;)</span><br><span class="line">                         .build();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        return null;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public int check() &#123;</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>然后访问health端点出现自定义信息:</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">status: &quot;UP&quot;,</span><br><span class="line">components: &#123;</span><br><span class="line">custom: &#123;</span><br><span class="line">status: &quot;UP&quot;,</span><br><span class="line">details: &#123;</span><br><span class="line">Status: &quot; UP&quot;,</span><br><span class="line">Error Code: 0,</span><br><span class="line">Description: &quot;自定义健康指针指向UP&quot;</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br><span class="line">db: &#123;</span><br><span class="line">status: &quot;UP&quot;,</span><br><span class="line">details: &#123;</span><br><span class="line">database: &quot;MySQL&quot;,</span><br><span class="line">result: 1,</span><br><span class="line">validationQuery: &quot;/* ping */ SELECT 1&quot;</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br><span class="line">diskSpace: &#123;</span><br><span class="line">status: &quot;UP&quot;,</span><br><span class="line">details: &#123;</span><br><span class="line">total: 248036454400,</span><br><span class="line">free: 224274227200,</span><br><span class="line">threshold: 10485760</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br><span class="line">ping: &#123;</span><br><span class="line">status: &quot;UP&quot;</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="自定义新的端点"><a href="#自定义新的端点" class="headerlink" title="自定义新的端点"></a>自定义新的端点</h2><p>你可以定义Actuator提供的端点之外的新端点.2.0版本只需要三个注解 <code>@RestControllerEndpoint、@ReadOperation、@Selector</code> </p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">/**</span><br><span class="line"> * create by zhangbo on 2019/11/8 0008</span><br><span class="line"> * 自定义新端点</span><br><span class="line"> */</span><br><span class="line">@Endpoint(id = &quot;mycustomEndpoint&quot;)</span><br><span class="line">@Component</span><br><span class="line">public class MyCustomEndpoint &#123;</span><br><span class="line"></span><br><span class="line">   	@ReadOperation</span><br><span class="line">    public String getMessage(@Selector String name) &#123;</span><br><span class="line">        return &quot;my name is&quot;+name;</span><br><span class="line">    &#125;</span><br><span class="line">    @ReadOperation</span><br><span class="line">    public String getMessage() &#123;</span><br><span class="line">        return &quot;hello,我是自定义的端点&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">    @WriteOperation</span><br><span class="line">    public String showMessage() &#123;</span><br><span class="line">        return &quot;hello,我是自定义的端点&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当然,这里面还有很多操作方法,暂未去研究. 这个<code>@ReadOperation</code>就是get请求方式.<code>@WriteOperation</code>就是post请求方式<br><code>id</code> 就是端点路径.</p>
<h1 id="通过HTTP管理监控端点"><a href="#通过HTTP管理监控端点" class="headerlink" title="通过HTTP管理监控端点"></a>通过HTTP管理监控端点</h1><h2 id="自定义服务端点"><a href="#自定义服务端点" class="headerlink" title="自定义服务端点"></a>自定义服务端点</h2><p>为了安全的目的你可以通过非标准端口号自定义服务端口号去暴露监控端点.可以通过<code>management.server.port</code>属性去配置</p>
<p>你也可以改变服务地址,通过<code>management.server.address</code>属性去严格限制端点在哪可以通过互联网访问.</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog">brad 随风起舞</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog/posts/45057/">https://zhangbo4881820.gitee.io/myblog/posts/45057/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhangbo4881820.gitee.io/myblog" target="_blank">静待花开</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myblog/tags/%E5%AE%9E%E6%88%98/">实战</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/posts/60287/" title="MordenJava01"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">MordenJava01</div></div></a></div><div class="next-post pull-right"><a href="/myblog/posts/58891/" title="markdown操作指引"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">markdown操作指引</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/myblog/posts/45226/" title="全栈开发(AngularJS原理)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-01</div><div class="title">全栈开发(AngularJS原理)</div></div></a></div><div><a href="/myblog/posts/21667/" title="全栈开发(RESTful和测试)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-06</div><div class="title">全栈开发(RESTful和测试)</div></div></a></div><div><a href="/myblog/posts/12008/" title="全栈开发(AngularJS)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-05</div><div class="title">全栈开发(AngularJS)</div></div></a></div><div><a href="/myblog/posts/20230/" title="全栈开发(Spring Security)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-04</div><div class="title">全栈开发(Spring Security)</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">brad 随风起舞</div><div class="author-info__description">有些事情需要一辈子的沉淀</div></div><div class="card-info-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:xxxxxx@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Spring-boot-actuator%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.</span> <span class="toc-text">Spring boot actuator介绍</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8Actuator%E6%A8%A1%E5%9D%97"><span class="toc-number">2.</span> <span class="toc-text">使用Actuator模块</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#info"><span class="toc-number">2.1.</span> <span class="toc-text">&#x2F;info</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#env"><span class="toc-number">2.2.</span> <span class="toc-text">&#x2F;env</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#metrics"><span class="toc-number">2.3.</span> <span class="toc-text">&#x2F;metrics</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#httpTrace"><span class="toc-number">2.4.</span> <span class="toc-text">&#x2F;httpTrace</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#health"><span class="toc-number">2.5.</span> <span class="toc-text">&#x2F;health</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%AB%AF%E7%82%B9"><span class="toc-number">3.</span> <span class="toc-text">自定义端点</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7"><span class="toc-number">3.1.</span> <span class="toc-text">自定义属性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89Health%E6%8C%87%E9%92%88"><span class="toc-number">3.2.</span> <span class="toc-text">自定义Health指针</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B0%E7%9A%84%E7%AB%AF%E7%82%B9"><span class="toc-number">3.3.</span> <span class="toc-text">自定义新的端点</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%80%9A%E8%BF%87HTTP%E7%AE%A1%E7%90%86%E7%9B%91%E6%8E%A7%E7%AB%AF%E7%82%B9"><span class="toc-number">4.</span> <span class="toc-text">通过HTTP管理监控端点</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%82%B9"><span class="toc-number">4.1.</span> <span class="toc-text">自定义服务端点</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/15695/" title="jenkins（1）">jenkins（1）</a><time datetime="2023-09-14T02:17:44.000Z" title="发表于 2023-09-14 10:17:44">2023-09-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/22012/" title="wsl的Ubuntu子系统（1）">wsl的Ubuntu子系统（1）</a><time datetime="2023-09-13T08:42:19.000Z" title="发表于 2023-09-13 16:42:19">2023-09-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/30302/" title="effective-java-(接口优于抽象类)">effective-java-(接口优于抽象类)</a><time datetime="2023-09-12T08:12:48.000Z" title="发表于 2023-09-12 16:12:48">2023-09-12</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/9473/" title="effective-java(创建和销毁对象--组合的形式优于继承)">effective-java(创建和销毁对象--组合的形式优于继承)</a><time datetime="2023-09-11T08:23:19.000Z" title="发表于 2023-09-11 16:23:19">2023-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/16107/" title="Hello World">Hello World</a><time datetime="2023-09-07T09:44:01.910Z" title="发表于 2023-09-07 17:44:01">2023-09-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By brad 随风起舞</div><div class="framework-info"><span>框架 </span><a href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="/myblog/js/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/myblog/js/search/local-search.js"></script></div></div></body></html>